/**
 * @author Fang Lu, fanglupku@gmail.com
 * 2011-5-12
 */
package com.autotag.stat;

import java.io.File;
import java.util.ArrayList;
import java.util.regex.Matcher;

import sei.pku.wsdl_analyzer.Operation;
import sei.pku.wsdl_analyzer.WSDLFile;
import sei.pku.wsdl_analyzer.WSDLFileAnalyzer;

import com.autotag.TokenExtractor;

public class TagStat {
	public static boolean isCamelString(String input) {
		if (input == null) {
			return false;
		}
		Matcher matcher_big = TokenExtractor.Camel_Border_Pattern.matcher(input);
		Matcher matcher_small = TokenExtractor.Camel_Content_Pattern.matcher(input);
		if (matcher_big.find() && matcher_small.find()) {
			return true;
		}
		return false;
	}

	public static void statCamelOP(String dir) {
		File WSDLDirFile = new File(dir);
		File[] files = WSDLDirFile.listFiles();
		WSDLFileAnalyzer wsdlFileAnalyzer = new WSDLFileAnalyzer();
		
		int camelNum = 0;
		for (int i=0; i<files.length; ++i){
			try {
				WSDLFile wFile = wsdlFileAnalyzer.analyzeWSDL(files[i].getAbsolutePath());
				ArrayList<Operation> opList = wFile.operations;
				boolean isCamel = false;
				for (int j=0; j<opList.size(); ++j){
					if (isCamelString(opList.get(j).operationName)){
						isCamel = true;
						break;
					}
				}
				if (isCamel == true){
					++ camelNum;
				}else{
					System.err.println(files[i].getName());
				}
//				System.out.println(i + "," + isCamel);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		System.out.println("total: " + camelNum + "/" + files.length);

	}
	public static void main(String args[]){
		statCamelOP("C:\\Users\\ftc\\Desktop\\ICSOC\\WSDL_FILE\\WSDL_FILE");
	}
}
